home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 May: Tool Chest / Developer CD Series May 1996 (Tool Chest) (Apple Computer) (1996).iso / Sample Code / Http Server / •OT_Classes / TNetworkEndpointDescriptor.cp < prev    next >
Encoding:
Text File  |  1996-01-11  |  3.5 KB  |  111 lines  |  [TEXT/CWIE]

  1. //    TNetworkEndpointDescriptor.cp - Macintosh OpenTransport network Endpoint Descriptor class object
  2. // 
  3. // Apple Macintosh Developer Technical Support
  4. // Written by:  Vinne Moscaritolo
  5. //
  6. //  Copyright (work in progress)  Apple Computer, Inc All rights reserved.
  7. //
  8. // You may incorporate this sample code into your applications without
  9. // restriction, though the sample code has been provided "AS IS" and the
  10. // responsibility for its operation is 100% yours.  However, what you are
  11. // not permitted to do is to redistribute the source as "DSC Sample Code"
  12. // after having made changes. If you're going to re-distribute the source,
  13. // we require that you make it clear in the source that the code was
  14. // descended from Apple Sample Code, but that you've made changes.
  15. // 
  16.  
  17. #include "TNetworkEndpointDescriptor.h"
  18. #include "TNetworkException.h"
  19.  
  20. #include "TAddrInet.h"
  21.  
  22.  
  23. // ---------------------------------------------------------------------------
  24. //     ~TNetworkEndpointDescriptor
  25. // ---------------------------------------------------------------------------
  26. //    Destructor
  27. TNetworkEndpointDescriptor::~TNetworkEndpointDescriptor()
  28. {    
  29.     if(fAddress) delete fAddress;                
  30.     if(fConfig) OTDestroyConfiguration(fConfig); 
  31. }
  32.  
  33.  
  34. // ---------------------------------------------------------------------------
  35. //     Stream
  36. // ---------------------------------------------------------------------------
  37. //    write out descriptor info to stream
  38.  
  39. void*  TNetworkEndpointDescriptor::Stream()
  40. {
  41.     return nil;
  42. }
  43.  
  44. // ---------------------------------------------------------------------------
  45. //     Unstream
  46. // ---------------------------------------------------------------------------
  47. //    read in descriptor info from stream
  48.  
  49.  
  50. void   TNetworkEndpointDescriptor::Unstream(void* in)
  51. {
  52. // ADD REAL CODE HERE    
  53.     ThrowIfOTInvalidConfig( fConfig  =  ::OTCreateConfiguration("tcp" ) );
  54.     fAddress = new TAddrInet(kOTAnyInetAddress, 80);
  55.     fState   = S_INIT;
  56.     
  57. }
  58.  
  59.  
  60. // ---------------------------------------------------------------------------
  61. //     GetConfiguration
  62. // ---------------------------------------------------------------------------
  63. //    Get Session Configutaration
  64.  
  65. OTConfiguration* TNetworkEndpointDescriptor::GetConfiguration() const
  66. {
  67.     ThrowIfOTInvalidConfig(fConfig);
  68.  
  69.     return OTCloneConfiguration( fConfig );
  70. }
  71.  
  72.  
  73.  
  74. // ---------------------------------------------------------------------------
  75. //     GetLocalAddress
  76. // ---------------------------------------------------------------------------
  77. //    Get Session Local Address
  78.  
  79. TAddr* TNetworkEndpointDescriptor::GetLocalAddress() 
  80. {
  81.     if( fState != S_INIT) ThrowMsg ("TNetworkEndpointDescriptor::GetLocalAddress - Not Initilized");
  82.     return fAddress;
  83. }
  84.  
  85. // ---------------------------------------------------------------------------
  86. //     TNetworkEndpointDescriptor::Filter( call )
  87. // ---------------------------------------------------------------------------
  88. //    Do you want to accept this connection 
  89.  
  90. Boolean TNetworkEndpointDescriptor::Filter(TCall* callInfo)
  91. {
  92.     return true;
  93. }
  94.  
  95.  
  96.  
  97. // ---------------------------------------------------------------------------
  98. //     TNetworkEndpointDescriptor::ValidateBind( reqAddr, retAddr )
  99. // ---------------------------------------------------------------------------
  100. //    Check if bind was acceptable
  101.  
  102. Boolean TNetworkEndpointDescriptor::ValidateBind (TBind* reqAddr, TBind* retAddr)
  103. {
  104.     InetAddress* request = (InetAddress*) reqAddr->addr.buf;
  105.     InetAddress* reply  =  (InetAddress*) retAddr->addr.buf;
  106.     
  107.     return ( request->fPort == reply->fPort );    ///**** FIX THIS LATER *****
  108. }
  109.  
  110.  
  111.